package com.jlu155.CourseManager.service;

import com.jlu155.CourseManager.Bean.PageRequest;
import com.jlu155.CourseManager.Bean.PageResult;
import com.jlu155.CourseManager.entity.Student;
import com.jlu155.CourseManager.repository.CollegeRepository;
import com.jlu155.CourseManager.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentService {
    //service在数据库访问层之上进行数据处理
    @Autowired
    private StudentRepository studentRepository;
    @Autowired
    private CollegeRepository collegeRepository;

    public PageResult<Student> getStudentPage(PageRequest pageRequest){
        PageResult<Student> pageResult=new PageResult<Student>();
        List<Student> students;
        students=studentRepository.findStudentByCond(pageRequest.getName(), pageRequest.getSid(),pageRequest.getCollege_id());
        pageResult.setPageList(students);
        pageResult.setPageNumber(students.size());
        pageResult.cutPage(pageRequest.getIndex(),pageRequest.getSize());
        return pageResult;
    }
    public boolean deleteStudent(Integer sid){
        try {
            studentRepository.deleteStudent(sid);
            return true;
        }catch (Exception e){
            return false;
        }
    }
    public boolean loginValidate(Integer sid,String password){
        if(password.equals(studentRepository.getPasswdById(sid))){
            return true;
        }
        return false;
    }
}
